/*
 * Copyright (C) 2013 Daniel Wasilew <daniel.wasilew@codeminer.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.codeminer.parts.database.derby;

import java.util.List;
import org.codeminer.database.DatabaseException;
import org.codeminer.parts.database.ArtistConnector;
import org.codeminer.parts.database.dao.AlbumDAO;
import org.codeminer.parts.database.dao.ArtistDAO;
import org.codeminer.parts.database.dao.SongDAO;
import org.codeminer.parts.library.Album;
import org.codeminer.parts.library.Artist;
import org.codeminer.parts.library.Song;

/**
 *
 * @author Daniel Wasilew <daniel.wasilew@codeminer.org>
 */
public class DerbyArtistStorageConnector extends DerbyStorageConnector implements ArtistConnector {

    @Override
    public Artist storeArtist(Artist artist) throws DatabaseException {
        long id = ArtistDAO.store(artist, getConnection());
        artist.setOid(id);
        return artist;
    }

    @Override
    public Artist getArtist(Artist searchCriteria) throws DatabaseException {
        return ArtistDAO.get(searchCriteria, getConnection());
    }

    @Override
    public List<Artist> getArtists(Song song) throws DatabaseException {
        return SongDAO.getArtistsForSong(song, getConnection());
    }

    @Override
    public boolean deleteArtist(Artist artist) throws DatabaseException {
        return ArtistDAO.delete(artist, getConnection());
    }

    @Override
    public boolean updateArtist(Artist artist) throws DatabaseException {
        return ArtistDAO.update(artist, getConnection());
    }

    @Override
    public List<Artist> getArtists(Album album) throws DatabaseException {
        return ArtistDAO.findArtistForAlbum(album, getConnection());
    }

    @Override
    public void addSongToArtist(Song song, Artist artist) throws DatabaseException {
        SongDAO.addArtistToSong(song, artist, getConnection());
    }

    @Override
    public void addAlbumToArtist(Album album, Artist artist) throws DatabaseException {
        AlbumDAO.addAlbumToArtist(album, artist, getConnection());
    }

    @Override
    public Class getAccessorDescription() {
        return ArtistConnector.class;
    }
    
    
}
